# -*- coding: utf-8 -*-
# @Time    : 2025/1/14 下午5:07
# @Author  : ysj
# @FileName: img2txt_del_none.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/ydscc?type=blog
import os


remove_file = False
data_filder = r'C:\Al\Software\AI_Model\Project\yolov5\yolov5\my_data\dataset_20250114_170308_yolo\dataset\labels'
img_dir = r'C:\Al\Software\AI_Model\Project\yolov5\yolov5\my_data\dataset_20250114_170308_yolo\dataset\images'
for file in os.listdir(data_filder):
    label_file = os.path.join(data_filder, file)
    with open(label_file, 'r') as f:
        content = f.read().split()
        if len(content) == 0:
            remove_file = True
    if remove_file:
        image_file = os.path.join(img_dir, file.replace('txt','jpg'))
        os.remove(label_file)
        if not os.path.exists(image_file):
            continue
        os.remove(image_file)
    else:
        continue



